import unittest
from api.employee import EmployeeAPI
from utiles import commin_assert


class TestEmployee(unittest.TestCase):
    employee_id = None
    # 初始化
    def setUp(self):
        self.employee = EmployeeAPI()

    # 添加员工
    def test01_add_employee(self):
        add_employee_data = {
                                "username": "username013",
                                "mobile": "13066778014",
                                "timeOfEntry": "2020-07-09",
                                "formOfEmployment": 1,
                                "workNumber": "12333015",
                                "departmentName": "销售",
                                "departmentId": "1266699057968001024",
                                "correctionTime": "2020-07-30T16:00:00.000Z"
                            }
        response = self.employee.add_employee(add_employee_data=add_employee_data)
        print(response.json())
        commin_assert(self, response, 200, True, 10000, "操作成功")

        TestEmployee.employee_id = response.json().get("data").get("id")

    def test02_update_employee(self):
        update_employee_data = {"username": "rose0709"}
        response = self.employee.modefy_employee(TestEmployee.employee_id, update_data=update_employee_data)
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        commin_assert(self, response, 200, True, 10000, "操作成功")

    def test03_get_employee(self):
        response = self.employee.get_employee(TestEmployee.employee_id)
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        commin_assert(self, response, 200, True, 10000, "操作成功")

    def test04_get_employee(self):
        response = self.employee.delete_employee(TestEmployee.employee_id)
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        commin_assert(self, response, 200, True, 10000, "操作成功")



